package com.tamecode.applicationcontext;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;

/**
 * @Author: Liqc
 * @Date: 2022/6/18 21:58
 */
public class MyBeanFactoryPostProcessor implements BeanFactoryPostProcessor {

    // 1.对Car <bean> 的 brand 属性配置信息进行“偷梁换柱”的加工操作
    public void postProcessBeanFactory(ConfigurableListableBeanFactory configurableListableBeanFactory) throws BeansException {
        BeanDefinition beanDefinition = configurableListableBeanFactory.getBeanDefinition("car");
        beanDefinition.getPropertyValues().addPropertyValue("brand", "BYD 宋pro");
        System.out.println("调用 BeanFactoryPostProcessor.postProcessBeanFactory()!");
    }

}
